<template>
  <div class="ElevatorRegiste pd30 propertyMaintenance">
    <div class="panelWrap">
      <div class="title flex flexac flexjcsb fs14 cfff fwb pl p-r-20">
        <div>电梯登记</div>
        <!-- <i class="el-icon-close" @click="handleCloseDialogUpdate"></i> -->
      </div>
      <div class="con">
        <div class="con-row flex flexac pl ">
          <div class="marginAuto flex flexac">
            <div class="inputLable inputLable1 flex flexac">
              <span class="name texttr"><span class="mustval">*</span>救援代码：</span>
              <el-input v-model="elevatorRegiste.rescueCode" class="input" placeholder="请输入救援代码" />
            </div>
            <div class="inputLable inputLable2 flex flexac m-l-60">
              <span class="name texttr"><span class="mustval">*</span>电梯注册代码：</span>
              <el-input v-model="elevatorRegiste.registerCode" class="input" placeholder="请输入电梯注册代码" />
            </div>
          </div>
        </div>
        <div class="con-row flex flexac pl ">
          <div class="marginAuto flex flexac">
            <div class="inputLable inputLable1 flex flexac  ">
              <span class="name texttr"><span class="mustval">*</span>注册登记机构：</span>
              <el-input v-model="elevatorRegiste.registerUnit" class="input" placeholder="请输入注册登记机构" />
            </div>
            <div class="inputLable inputLable2 flex flexac m-l-60">
              <span class="name texttr">注册登记日期：</span>
              <!-- <el-input class="input" v-model="elevatorRegiste.zipCode" placeholder="请输入注册登记日期"></el-input> -->
              <el-date-picker v-model="elevatorRegiste.registerDate" format="yyyy-MM-dd" value-format="yyyy-MM-dd" type="date" placeholder="请选择注册登记日期" />
            </div>
          </div>
        </div>

        <div class="con-row flex flexac pl ">
          <div class="marginAuto flex flexac">
            <div class="inputLable inputLable2 flex flexac ">
              <span class="name texttr">注册更新日期：</span>
              <!-- <el-input class="input" type="number" v-model="elevatorRegiste.phone" placeholder="请输入注册更新日期"></el-input> -->
              <el-date-picker v-model="elevatorRegiste.registerUpdateDate" format="yyyy-MM-dd" value-format="yyyy-MM-dd" type="date" placeholder="请选择注册更新日期" />
            </div>
            <div class="inputLable inputLable1 flex flexac m-l-60">
              <span class="name texttr"><span class="mustval">*</span>单位内部编号：</span>
              <el-input v-model="elevatorRegiste.internaNo" class="input" placeholder="请输入单位内部编号" />
            </div>
          </div>
        </div>
        <div class="con-row flex flexac pl ">
          <div class="marginAuto flex flexac">
            <div class="inputLable inputLable2 flex flexac ">
              <span class="name texttr"><span class="mustval">*</span>出厂编号：</span>
              <el-input v-model="elevatorRegiste.factoryNo" class="input" type="number" placeholder="请输入出厂编号" />
            </div>
            <div class="inputLable inputLable1 flex flexac m-l-60">
              <span class="name texttr">厂车牌照编号：</span>
              <el-input v-model="elevatorRegiste.carNo" class="input" placeholder="请输入厂车牌照编号" />
            </div>
          </div>
        </div>
        <div class="con-row flex flexac pl ">
          <div class="marginAuto flex flexac">
            <div class="inputLable inputLable1 flex flexac ">
              <span class="name texttr"><span class="mustval">*</span>安装地址：</span>
              <el-input v-model="elevatorRegiste.address" class="input" placeholder="请输入安装地址" />
            </div>
            <div class="inputLable inputLable1 flex flexac m-l-60">
              <span class="name texttr"><span class="mustval">*</span>安装坐标：</span>
              <el-input class="input coordinateRead" :value="getcoordinate" readonly placeholder="请选择安装坐标" />
              <el-button class="locationBtn" @click="choiceCoordinate=true">定位</el-button>
            </div>
          </div>
        </div>
        <div class="con-row flex flexac pl ">
          <div class="marginAuto flex flexac">
            <div class="inputLable inputLable2 flex flexac ">
              <span class="name texttr">操作人员：</span>
              <el-input v-model="elevatorRegiste.operator" class="input" type="number" placeholder="请输入操作人员" />
            </div>
            <div class="inputLable inputLable2 flex flexac m-l-60">
              <span class="name texttr"><span class="mustval">*</span>使用状态：</span>
              <el-select v-model="elevatorRegiste.useState" placeholder="请选择使用状态">
                <el-option v-for="item in usageState" :key="item.value" :label="item.label" :value="item.value" />
              </el-select>
            </div>
          </div>
        </div>
        <div class="con-row flex flexac pl ">
          <div class="marginAuto flex flexac">
            <div class="inputLable inputLable2 flex flexac ">
              <span class="name texttr">电梯使用场合：</span>
              <!-- <el-input class="input" type="number" v-model="elevatorRegiste.legalPersonPhone" placeholder="请输入电梯使用场合"></el-input> -->
              <el-select v-model="elevatorRegiste.usePlaceName" placeholder="请选择电梯使用场合">
                <el-option v-for="item in usageOccasion" :key="item.value" :label="item.label" :value="item.value" />
              </el-select>
            </div>
            <div class="inputLable inputLable2 flex flexac m-l-60">
              <span class="name texttr"><span class="mustval">*</span>电梯重要等级：</span>
              <el-select v-model="elevatorRegiste.importantLevel" placeholder="请输入电梯重要等级">
                <el-option v-for="item in majorLevel" :key="item.value" :label="item.label" :value="item.value" />
              </el-select>
            </div>
          </div>
        </div>
        <div class="con-row flex flexac pl ">
          <div class="marginAuto flex flexac">
            <div class="inputLable inputLable2 flex flexac ">
              <span class="name texttr">下次校验日期：</span>
              <!-- <el-input class="input" type="number" v-model="elevatorRegiste.legalPersonPhone" placeholder="请输入下次校验日期"></el-input> -->
              <el-date-picker v-model="elevatorRegiste.nextInspectionDate" format="yyyy-MM-dd" value-format="yyyy-MM-dd" type="date" placeholder="请选择下次校验日期" />
            </div>
          </div>
        </div>
        <div class="con-row flex flexac pl ">
          <div class="inputLable inputLable2 flex flexac ">
            <span class="name texttr"><span class="mustval">*</span>行政区域：</span>
            <city :region-code="elevatorRegiste.regionCode" @emitCity="onSendcity" />
          </div>
        </div>

      </div>

      <div class="flex  footerBtn m-t-35 ">
        <el-button class="defaultbtn saveBtn" @click="handleSave">保存</el-button>
        <el-button class="defaultbtn clsoeBtn" @click="handleCloseDialogUpdate">关闭</el-button>
      </div>
    </div>
    <el-dialog v-if="choiceCoordinate" custom-class="coordinateWrap" :close-on-click-modal="false" :visible.sync="choiceCoordinate">
      <coordinate />
    </el-dialog>
  </div>
</template>

<script>

import { elevatorCreateAdd } from '@/api/elevator/elevator'
import { showNotice, successNotice, checkMobile } from '@/utils/toolclass'
import city from '@/components/city'
import coordinate from '@/components/coordinate'
import bus from '@/utils/bus'

export default {
  components: {
    city, coordinate
  },
  props: {
    addFactory: {
      type: Object
    },
    isEdit: {
      type: Boolean
    }
  },
  data() {
    return {
      elevatorRegiste: {
        id: '',
        rescueCode: '213213',
        registerCode: '12312321',
        registerUnit: '213123',
        registerDate: '2020-07-15',
        registerUpdateDate: '2020-07-15',
        internaNo: '12321',
        factoryNo: '213124',
        carNo: '1231231',
        address: 'dadada',
        latitude: '',
        longitude: '',
        operator: '1232131',
        useState: 1,
        usePlaceName: 1,
        importantLevel: 1,
        nextInspectionDate: '2020-07-15',
        regionCode: ''

      },
      choiceCoordinate: false,
      usageState: [{
        value: 0,
        label: '在用'
      }, {
        value: 1,
        label: '停用'
      }, {
        value: 2,
        label: '不属'
      }, {
        value: 3,
        label: '不明'
      }, {
        value: 4,
        label: '公告注销'
      }, {
        value: 5,
        label: '提交监察'
      }, {
        value: 6,
        label: '正在大修'
      }, {
        value: 7,
        label: '正在安装'
      }, {
        value: 8,
        label: '正在改造'
      }],
      value: '',
      usageOccasion: [{
        value: 0,
        label: '办公楼宇'
      }, {
        value: 1,
        label: '商场超市'
      }, {
        value: 2,
        label: '宾馆饭店'
      }, {
        value: 3,
        label: '医院'
      }, {
        value: 4,
        label: '学校'
      }, {
        value: 5,
        label: '住宅'
      }, {
        value: 6,
        label: '交通场所'
      }, {
        value: 7,
        label: '文体娱乐馆'
      }, {
        value: 8,
        label: '其他场所'
      }],
      majorLevel: [
        {
          value: 1,
          label: '高'
        }, {
          value: 2,
          label: '一般'
        }
      ]
    }
  },
  computed: {
    getcoordinate: function() {
      if (this.elevatorRegiste.longitude == '' || this.elevatorRegiste.latitude == '') {
        return ''
      } else {
        return ('' + this.elevatorRegiste.longitude) + ',' + (this.elevatorRegiste.latitude + '')
      }
    }
  },
  created() {
    this.onCloseCoordinate()
    this.onSendCoordinate()
    console.log('storage--------')
    console.log(storage)
  },
  mounted() {
    this.$storage.set('upUrl', JSON.stringify({ 'path': '/elevatordaDossier/ElevatorRegiste/index' }))
  },
  methods: {
    onSendCoordinate() {
      bus.$on('sendCoordinate', (data) => {
        this.elevatorRegiste.longitude = data.lng
        this.elevatorRegiste.latitude = data.lat
        this.handleCloseCoordinate()
      })
      bus.$on('sendCoordinateAddress', (data) => {
        // console.log('sendCoordinateAddress')
        // console.log(data)
        this.elevatorRegiste.address = (data.province === undefined ? '' : data.province) + '' + (data.city === undefined ? '' : data.city) + '' + (data.title === undefined ? '' : data.title)
      })
    },
    onCloseCoordinate() {
      bus.$on('closeCoordinate', (data) => {
        this.handleCloseCoordinate()
      })
    },
    handleCloseCoordinate() {
      this.choiceCoordinate = false
    },
    onSendcity(res) {
      this.elevatorRegiste.regionCode = res.area
    },
    handleUpdate() {
      simpleViewUpdate(this.addFactory).then((res) => {
        if (res.code == '000000') {
          showNotice('success', '提示', '保存成功')
          this.$emit('handleRefresh')
          this.$emit('handleCloseDialog')
        }
      })
    },
    handleSave() {
      if (this.elevatorRegiste.rescueCode == '') {
        showNotice('error', '提示', '救援代码为空')
        return
      }
      if (this.elevatorRegiste.registerCode == '') {
        showNotice('error', '提示', '电梯注册代码为空')
        return
      }
      if (this.elevatorRegiste.registerUnit == '') {
        showNotice('error', '提示', '注册登记机构为空')
        return
      }

      if (this.elevatorRegiste.internaNo == '') {
        showNotice('error', '提示', '单位内部编号为空')
        return
      }
      if (this.elevatorRegiste.factoryNo == '') {
        showNotice('error', '提示', '出厂编号为空')
        return
      }
      if (this.elevatorRegiste.address == '') {
        showNotice('error', '提示', '安装地址为空')
        return
      }
      if (this.elevatorRegiste.latitude == '' || this.elevatorRegiste.longitude == '') {
        showNotice('error', '提示', '安装坐标为空')
        return
      }
      if (this.elevatorRegiste.useState == '') {
        showNotice('error', '提示', '使用状态为空')
        return
      }
      if (this.elevatorRegiste.importantLevel == '') {
        showNotice('error', '提示', '电梯重要等级为空')
        return
      }
      if (this.elevatorRegiste.regionCode == '') {
        showNotice('error', '提示', '行政区域为空')
        return
      }
      this.handleelevatorRegisteAdd(this.elevatorRegiste)
    },
    handleCloseDialog() {
      console.log('子组件关闭')
      this.$emit('handleCloseDialog')
    },
    handleCloseDialogUpdate() {
      this.$emit('handleRefresh')
      this.$emit('handleCloseDialog')
    },
    handleelevatorRegisteAdd(obj) {
      elevatorCreateAdd(obj).then((res) => {
        if (res.code == '000000') {
          showNotice('success', '提示', '保存成功!')
        }
      })
    }
  }
}
</script>

<style rel='stylesheet/scss' lang='scss' scoped>
@import "@/styles/addtable.scss";
.showMapBtn{
  margin-left: 10px !important;
}
// .footerBtn{
//     padding-left: 0 !important;
// }
</style>
